package com.mirabelle.juice.model;

import java.io.Serializable;
import javax.persistence.*;

import java.util.Date;
import java.util.List;

/**
 * The persistent class for the author database table.
 * 
 */
@Entity
@Table(name = "author")
public class Author implements Serializable {
	private static final long serialVersionUID = 1L;
	private Integer id;
	private Boolean admin;
	private String comment;
	private Date created;
	private String firstName;
	private String lastName;
	private String nickName;
	private String mail;
	private Date modified;
	private String password;
	private List<Comment> comments;
	private List<Collection> collections;
	private List<Recipe> recipes;

	public Author() {
	}

	@Id
	@SequenceGenerator(name = "AUTHOR_ID_GENERATOR", sequenceName = "seq_author_id", allocationSize = 1)
	@GeneratedValue(strategy = GenerationType.IDENTITY, generator = "AUTHOR_ID_GENERATOR")
	@Column(unique = true, nullable = false)
	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@Column(nullable = false)
	public Boolean getAdmin() {
		return this.admin;
	}

	public void setAdmin(Boolean admin) {
		this.admin = admin;
	}

	@Column(length = 2147483647)
	public String getComment() {
		return this.comment;
	}

	public void setComment(String comment) {
		this.comment = comment;
	}
	
	@OneToMany(mappedBy="author")
	public List<Comment> getComments() {
		return this.comments;
	}

	public void setComments(List<Comment> comments) {
		this.comments = comments;
	}
	
	public Comment addComment(Comment comment) {
		getComments().add(comment);
		comment.setAuthor(this);

		return comment;
	}

	public Comment removeComment(Comment comment) {
		getComments().remove(comment);
		comment.setAuthor(null);

		return comment;
	}

	@Temporal(TemporalType.DATE)
	@Column(nullable = false)
	public Date getCreated() {
		return this.created;
	}

	public void setCreated(Date created) {
		this.created = created;
	}

	@Column(name = "first_name", nullable = false, length = 255)
	public String getFirstName() {
		return this.firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	@Column(name = "last_name", nullable = false, length = 255)
	public String getLastName() {
		return this.lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}
	
	@Column(name = "nick_name", unique = true, nullable = false, length = 255)
	public String getNickName() {
		return this.nickName;
	}

	public void setNickName(String nickName) {
		this.nickName = nickName;
	}

	@Column(unique = true, length = 255)
	public String getMail() {
		return this.mail;
	}

	public void setMail(String mail) {
		this.mail = mail;
	}

	@Temporal(TemporalType.DATE)
	public Date getModified() {
		return this.modified;
	}

	public void setModified(Date modified) {
		this.modified = modified;
	}

	@Column(nullable = false, length = 255)
	public String getPassword() {
		return this.password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	// bi-directional many-to-one association to Recipe
	@OneToMany(mappedBy = "author")
	public List<Recipe> getRecipes() {
		return this.recipes;
	}

	public void setRecipes(List<Recipe> recipes) {
		this.recipes = recipes;
	}

	// bi-directional many-to-one association to Collection
	@OneToMany(mappedBy = "author")
	public List<Collection> getCollections() {
		return this.collections;
	}

	public void setCollections(List<Collection> collections) {
		this.collections = collections;
	}

	public Recipe addRecipe(Recipe recipe) {
		getRecipes().add(recipe);
		recipe.setAuthor(this);

		return recipe;
	}

	public Recipe removeRecipe(Recipe recipe) {
		getRecipes().remove(recipe);
		recipe.setAuthor(null);

		return recipe;
	}

}